package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AppAttachment;
import com.ruoyi.system.service.IAppAttachmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文件Controller
 *
 * @author ruoyi
 * @date 2023-02-28
 */
@RestController
@RequestMapping("/system/attachment")
public class AppAttachmentController extends BaseController {

    @Autowired
    private IAppAttachmentService appAttachmentService;

    /**
     * 查询文件列表
     */
    @PreAuthorize("@ss.hasPermi('system:attachment:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppAttachment appAttachment) {
        startPage();
        List<AppAttachment> list = appAttachmentService.selectAppAttachmentList(appAttachment);
        return getDataTable(list);
    }

    /**
     * 导出文件列表
     */
    @PreAuthorize("@ss.hasPermi('system:attachment:export')")
    @Log(title = "文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppAttachment appAttachment) {
        List<AppAttachment> list = appAttachmentService.selectAppAttachmentList(appAttachment);
        ExcelUtil<AppAttachment> util = new ExcelUtil<AppAttachment>(AppAttachment.class);
        util.exportExcel(response, list, "文件数据");
    }

    /**
     * 获取文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:attachment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appAttachmentService.selectAppAttachmentById(id));
    }

    /**
     * 新增文件
     */
    @PreAuthorize("@ss.hasPermi('system:attachment:add')")
    @Log(title = "文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppAttachment appAttachment) {
        return toAjax(appAttachmentService.insertAppAttachment(appAttachment));
    }

    /**
     * 修改文件
     */
    @PreAuthorize("@ss.hasPermi('system:attachment:edit')")
    @Log(title = "文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppAttachment appAttachment) {
        return toAjax(appAttachmentService.updateAppAttachment(appAttachment));
    }

    /**
     * 删除文件
     */
    @PreAuthorize("@ss.hasPermi('system:attachment:remove')")
    @Log(title = "文件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appAttachmentService.deleteAppAttachmentByIds(ids));
    }


//    @Resource
//    private AppNewsDetailedServiceImpl appNewsDetailedService;
//    /**
//     * 查询新闻列表
//     */
//    @RequestMapping(value = "getNewList", method = {RequestMethod.GET, RequestMethod.POST})
//    @ApiOperation("获取新闻列表")
//    public AjaxResult getNewList(AppNewsDetailed appNewsDetailed) {
//        startPage();
//        List<AppNewsDetailed> list = appNewsDetailedService.findList(appNewsDetailed);
//        return AjaxResult.ok(0, "", getDataTable(list));
//    }
//
//    /**
//     * 根据新闻id查询新闻详情
//     *
//     * @param id
//     * @return
//     */
//    @RequestMapping(value = "getNewListById", method = {RequestMethod.GET, RequestMethod.POST})
//    @ApiOperation("获取新闻信息")
//    public AjaxResult getCollectInfo(@ApiParam("新闻id") @RequestParam Long id) {
//        Map<String, Object> map = new HashMap<>();
//        map.put("newDetailed", appNewsDetailedService.getById(id));
//        return AjaxResult.ok(0, "", map);
//    }
//@Resource
//private AppNewsTypesServiceImpl appNewsTypesService;
//    /**
//     * 获取新闻类型
//     * @return
//     */
//    @RequestMapping(value = "getNewTypeList", method = {RequestMethod.GET, RequestMethod.POST})
//    @ApiOperation("获取新闻类型")
//    public AjaxResult getNewTypeList( ) {
//        Map<String, Object> map = new HashMap<>();
//
//        map.put("newTypes", appNewsTypesService.findList(new AppNewsTypes()));
//        return AjaxResult.ok(0, "", map);
//    }



}
